package com.ruoyi.tactics.algorithm;

import com.ruoyi.tactics.ZodiacResult;
import com.ruoyi.tactics.utils.CombineUtil;

import java.util.*;

/**
 * 二中二
 */
public class EZEAlgorithm extends AbstractAlgorithm {
    @Override
    public Boolean isWin(ZodiacResult zodiacResult, String... code) {
        List<Integer> pms = zodiacResult.getPm();
        return isContains(pms, Integer.parseInt(code[0]), Integer.parseInt(code[1]));
    }

    private Boolean isContains(List<Integer> pms, Integer... codes) {
        System.out.println("中奖号码:" + pms + "号码:" + Arrays.asList(codes));
        Set<Integer> pmSet = new HashSet<>();
        pmSet.addAll(pms);
        Set<Integer> codeSet = new HashSet<>();
        codeSet.addAll(Arrays.asList(codes));
        pmSet.retainAll(codeSet);
        return pmSet.size() == 2;
    }


//    public static void main(String[] args) {
//        Integer[] nums = {1, 2, 3, 4, 5, 6};
//
//        List<List<Integer>> combinations = CombineUtil.combine(nums, 2);
//
//        System.out.println("所有组合是：");
//        for (List<Integer> combination : combinations) {
//            System.out.println(combination);
//        }
//        System.out.println("所有组合有：" + combinations.size() + "组");
//
//    }

    public static void main(String[] args) {
        EZEAlgorithm algorithm = new EZEAlgorithm();
        ZodiacResult zodiacResult = new ZodiacResult();
        zodiacResult.setPm(Arrays.asList(1, 2, 3, 4, 5));

        List<List<Integer>> combinations = CombineUtil.combine(Arrays.asList(1, 2, 4, 5,9,10,46).toArray(new Integer[0]), 2);
        Integer num = 0;
        for (List<Integer> combination : combinations) {
            Boolean isWin = algorithm.isWin(zodiacResult, combination.stream()
                    .map(String::valueOf)
                    .toArray(String[]::new));
            num += isWin ? 1 : 0;
        }
        System.out.println(combinations.size()+"组，中奖:"+num+"组");
    }
}
